package com.edou.member.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.edou.base.page.PageResult;
import com.edou.member.dao.IMemberUserRoleDao;
import com.edou.member.entity.MemberUserRole;
import com.edou.member.service.IMemberUserRoleService;

import com.edou.member.dto.MemberUserRoleCondition;

/**
 * 会员角色关联表
 * @creator     
 * @create-time 2016/5/13 21:54:38
 * @email admin@edou.com
 * @company www.edou.com
 * @version 1.0
 */
@Service("memberUserRoleServiceImpl")
@Transactional(value = "transactionManager")
public class MemberUserRoleServiceImpl implements IMemberUserRoleService{

	@Resource(name = "memberUserRoleDaoImpl")
	private IMemberUserRoleDao memberUserRoleDao;

	/**
	 * 查询所有会员角色关联表
	 */
	public List<MemberUserRole> listMemberUserRoleAll(){
		return memberUserRoleDao.listMemberUserRoleAll();
	}

	/**
	 * 分页查询
	 * @param pageResult 分页对象
	 * @param condition 查询条件类
	 */
	public void listMemberUserRoleByPage(PageResult<MemberUserRole> pageResult,MemberUserRoleCondition condition){
		int rows = memberUserRoleDao.listMemberUserRoleByPageCount(condition);
		pageResult.setRows(rows);

		RowBounds rowBounds = new RowBounds(pageResult.getCurrentPageIndex(),pageResult.getPageSize());
		List<MemberUserRole> list = memberUserRoleDao.listMemberUserRoleByPage(rowBounds,condition);
		pageResult.setResult(list);
	}

	/**
	 * 根据ID查询
	 * @param id 主键
	 * @return 会员角色关联表
	 */
	public MemberUserRole getMemberUserRoleById(String id){
		return memberUserRoleDao.getMemberUserRoleById(id);
	}

	/**
	 * 新增
	 * @param item 会员角色关联表
	 */
	public void add(MemberUserRole item){
		memberUserRoleDao.add(item);
	}

	/**
	 * 修改
	 * @param item 会员角色关联表
	 */
	public void update(MemberUserRole item){
		memberUserRoleDao.update(item);
	}

	/**
	 * 根据ID集合批量删除
	 * @param ids ID集合
	 */
	public void delByIds(String[] ids){
		memberUserRoleDao.delByIds(ids);
	}

	/**
	 * 根据memberUserId进行删除信息
	 */
	public void delByUserId(String memberUserId) {
		memberUserRoleDao.delByUserId(memberUserId);
	}

	/**
	 * 根据会员id查找会员角色 
	 */
	public MemberUserRole getMemberUserRoleByUserId(String memberUserId) {
		return memberUserRoleDao.getMemberUserRoleByUserId(memberUserId);
	}

	@Override
	public List<MemberUserRole> listMemberUserRoleByUserId(String memberUserId) {
		return memberUserRoleDao.listMemberUserRoleByUserId(memberUserId);
	}

	/**
	 *  根据会员ID,角色编码删除该关系 
	 */
	@Override
	public void delByUserIdAndCode(String memberUserId, String code) {
		memberUserRoleDao.delByUserIdAndCode(memberUserId, code);
	}

}

